<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="../../baselist.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<html>
<head>
    <title></title>
    <script type="text/javascript" src="${ctx }/js/jquery.min.js"></script>
    <script>
        function isOnlyChecked() {
            var checkBoxArray = document.getElementsByName('id');
            var count = 0;
            for (var index = 0; index < checkBoxArray.length; index++) {
                if (checkBoxArray[index].checked) {
                    count++;
                }
            }
            //jquery
            //var count = $("[input name='id']:checked").size();
            if (count == 1)
                return true;
            else
                return false;
        }

        function toView() {
            if (isOnlyChecked()) {
                formSubmit('${ctx}/userss/toview', '_self');
            } else {
                alert("请先选择一项并且只能选择一项，再进行操作！");
            }
        }

        //实现更新
        function toUpdate() {
            if (isOnlyChecked()) {
                formSubmit('${ctx}/userss/toupdate', '_self');
            } else {
                alert("请先选择一项并且只能选择一项，再进行操作！");
            }
        }

        //实现角色
        function toRole() {
            if (isOnlyChecked()) {
                formSubmit('${ctx}/userss/torole', '_self');
            } else {
                alert("请先选择一项并且只能选择一项，再进行操作！");
            }
        }


        function delUser(){
            // 获取部门编号  根据部门编号 删除 可以进行 多条删除
            var userIds = new Array();
            var checkBoxs = $("input[name='id']:checked");
            if(checkBoxs.length==0){
                alert("请至少选中一条记录进行删除！")
                return ;
            }
            // 把选中的复选框的值 即部门编号  放在deptIds 数组中
            for(var i=0;i<checkBoxs.length;i++){
                userIds.push(checkBoxs[i].value);
            }
            // 把放着部门编号的 数组  deptIds  转成 字符串   便于向后台传递
            //  [1,2,3]   ---->   1,2,3
            userIds = userIds.join(",");

            var ajax = {
                url:"${ctx}/userss/delete",
                data:{"userIds":userIds},
                success:function (data){
                    if(data.status==200){
                        alert(data.msg);
                        formSubmit('${ctx}/userss/list','_self');
                    }else{
                        alert("该部门下有子部门或者员工，不能删除"+ data.data)
                    }
                }
            };

            $.ajax(ajax);

        }
    </script>
</head>

<body>
<form name="icform" method="post">
    <div id="menubar">
        <div id="middleMenubar">
            <div id="innerMenubar">
                <div id="navMenubar">
                    <ul>
                        <li id="view"><a href="javascript:toView()">查看</a></li>
                        <li id="new"><a href="#" onclick="formSubmit('${ctx}/userss/tocreate','_self');this.blur();">新增</a>
                        </li>
                        <li id="update"><a href="#" onclick="javascript:toUpdate()">修改</a></li>
                        <li id="updateRole"><a href="#"
                                           onclick="toRole()">角色</a></li>
                        <li id="update"><a href="#"
                                           onclick="delUser();this.blur();">删除</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="textbox" id="centerTextbox">
        <div class="textbox-header">
            <div class="textbox-inner-header">
                <div class="textbox-title">
                    用户列表
                </div>
            </div>
        </div>
    </div>
    <div>


        <div class="eXtremeTable">
            <table id="ec_table" class="tableRegion" width="98%">
                <thead>
                <tr>
                    <td class="tableHeader"><input type="checkbox" name="selid" onclick="checkAll('id',this)"></td>
                    <td class="tableHeader">序号</td>
                    <td class="tableHeader">用户名</td>
                    <td class="tableHeader">状态</td>
                </tr>
                </thead>
                <tbody class="tableBody">
                <jsp:include page="../../page.jsp"></jsp:include>

                <c:forEach items="${pb.datas}" var="o" varStatus="status">
                    <tr class="odd" onmouseover="this.className='highlight'" onmouseout="this.className='odd'">
                        <td><input type="checkbox" name="id" value="${o.userId}"/></td>
                        <td>${status.index+1}</td>
                        <td><a href="userAction_toview?id=${o.userId}">${o.userName}</a></td>
                        <td>${o.state==1?'启用':'停用'}</td>
                    </tr>
                </c:forEach>

                </tbody>
            </table>
        </div>

    </div>


</form>
</body>
</html>

